package cst.neu.yuejian_31.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.bean.TrainBean;
import cst.neu.yuejian_31.iface.TrainDetailListener;
import cst.neu.yuejian_31.model.TrainModel;

public class TrainDetailActivity extends BaseActivity implements View.OnClickListener,TrainDetailListener {
    private Context context=null;
    private String trainId,trainaddress,trainmoney,trainname,trainpic;
    private String actiName;
    private TextView trainName,trainIntro,trainAddress,trainPrice,trainTime,trainNotic;
    private ImageView trainPic;
    private Button btn_join;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_detail);
        initView();
        getTrainId();
        initdata();
    }
    private void initView() {
        trainName= (TextView) findViewById(R.id.train_name);
        trainIntro= (TextView) findViewById(R.id.train_intro);
        btn_join=(Button)findViewById(R.id.button_train_join);
        trainPic=(ImageView) findViewById(R.id.tarinDetail_pic);
        trainPrice=(TextView)findViewById(R.id.train_price);
        trainTime=(TextView)findViewById(R.id.train_time);
        trainNotic=(TextView)findViewById(R.id.train_notic);
        btn_join.setOnClickListener(this);
    }

    private void getTrainId() {
        Intent intent=getIntent();
        trainId=intent.getStringExtra("train_id");
        Toast.makeText(TrainDetailActivity.this,trainId, Toast.LENGTH_SHORT).show();

    }

    private void initdata() {
        TrainModel model=new TrainModel();
        model.gettraindetail(trainId,this);
        Intent intent=getIntent();
        trainId=intent.getStringExtra("train_id");
        trainaddress=intent.getStringExtra("train_address");
        trainmoney=intent.getStringExtra("train_money");
        trainname=intent.getStringExtra("train_name");
        trainpic=intent.getStringExtra("train_pic");
    }




    @Override
    public void onResponse(TrainBean trainBean) {
        trainName.setText(trainBean.getTrain_name());
        trainIntro.setText(trainBean.getTrain_intro());
        trainPrice.setText(trainBean.getTrain_price());
       trainTime.setText(trainBean.getTrain_time());
        trainNotic.setText(trainBean.getTrain_notic());
     Picasso.with(TrainDetailActivity.this).load(Constant.TRAIN_URL+trainBean.getTrain_pic().toString()).into(trainPic);
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_train_join:
                Intent intent=new Intent(TrainDetailActivity.this,TrainOrderActivity.class);
                intent.putExtra("train_id",trainId);
                intent.putExtra("train_name",trainname);
                intent.putExtra("train_money",trainmoney);
                intent.putExtra("train_address",trainaddress);
                intent.putExtra("train_pic",trainpic);
                startActivity(intent);
                break;
        }
    }
}


